<?php
	class services{
		public $js = array('js/services.js');
		public $css = array();
		public $onload = '';
		
		private $result;
		
		function echo_javascript(){
			
		}
		
		function echo_izq(){
			echo "&nbsp;";
		}
		
		function echo_centro(){
			$path = '/etc/init.d/';
			$files = array();
			
			$d = opendir($path);
			
			while($file = readdir($d)){
				if($file != '.' && $file != '..')
					$files[] = $file;
			}
			
			closedir($d);
			
			sort($files);
			
			echo "<p>" . $this->result . "</p>";
			echo "<form method='post' action='index.php?controller=services&action=saction' id='services_form'><table class='services'>
				<tr><th>Service</th><th>State</th><th>Actions</th></tr>";
			
			foreach($files as $file){
				echo "<tr><td>$file</td><td>&nbsp;</td><td>
					<input type='button' value='Start' onclick='start()'/>
					<input type='button' value='Stop' onclick='stop()'/>
					<input type='button' value='Reload' onclick='reload()'/>
					<input type='button' value='Restart' onclick='restart()'/>
					</td></tr>\n";
			}
			echo "</table>
				<input type='hidden' value='' name='service' id='service'/>
				<input type='hidden' value='' name='saction' id='saction'/>
				</form>";
		}
		
		function echo_der(){
			echo "&nbsp;";
		}
		
		function saction(){
			$service = $_POST['service'];
			$saction = $_POST['saction'];
			
			if($service != null && $saction != null){
				$this->result = exec("service $service $action");
			}
		}
	}
?>